import Axios from 'axios'
import {ElMessage} from 'element-plus'
// 初始化配置
const http = Axios.create({
    baseURL:import.meta.env.VITE_BASE_URL,
    timeout:6000,
    headers:{
        "Content-Type":"application/json",
    }
})

/**
 * 请求拦截器
 */
http.interceptors.request.use(config => {
    return config
},(error) => {
    return Promise.reject(error)
})
/**
 * 响应拦截器 
 */
http.interceptors.response.use(response => {
    const {code, msg} = response.data
    if(code === 0) {
        return Promise.resolve(response.data)
    } else {
        ElMessage({type:'error',message:msg,})
        return Promise.reject(response.data)
    }
},(error) => {
    return Promise.reject(error)
})

export default http

